import { pushRequestInterceptor, pushResponseInterceptor } from 'lfun-bg-comp';
// import { message } from 'antd';
// import utils from '@/utils';

// pushRequestInterceptor('get:/school/v1/storage/school-upload-uri', e => {
//   if (e.params.sourceFileName) {
//     e.params = { filename: e.params.sourceFileName };
//     return e;
//   }
//   e.params = {
//     filename: `${utils.getUserId()}-${new Date().getTime()}${e.params.fileSuffix}`,
//     file_size: e.params.size,
//   };
//   return e;
// });

// pushResponseInterceptor('get:/school/v1/storage/school-upload-uri', e => {
//   if (e.error_code) {
//     message.error(e.user_message);
//     return null;
//   }
//   return {
//     url: e.upload_url,
//     //|| 'https://minio.f123.pub/demo-private/386664652.xlsx?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=gEfa1XHFBywBvobP%2F20240627%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20240627T064758Z&X-Amz-Expires=86400&X-Amz-SignedHeaders=host&X-Amz-Signature=dda3914e70fe705709e139715e1fba1898c2bb64f805cf620efd5763f67189cc',
//     downloadUrl: e.download_url,
//     //|| 'https://minio.f123.pub/demo-private/386664652.xlsx?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=gEfa1XHFBywBvobP%2F20240627%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20240627T064758Z&X-Amz-Expires=86400&X-Amz-SignedHeaders=host&X-Amz-Signature=ce45d2e76e199368943a7dba28367a788454c9fb7e0c9ee5e1c8d6866cda7df5',
//     fileid: e.file_id || 1,
//     success: true,
//   };
// });

pushRequestInterceptor('get:/school/v1/task/page', e => {
  e.params = {
    page: e.params.pageIndex,
    per_page: e.params.pageSize,
    task_id: e.params.taskNo,
    state: e.params.taskState,
    operator: e.params.operate,
    app_name: e.params.app_name,
    module: e.params.chunk,
  };
  return e;
});
pushResponseInterceptor('get:/school/v1/task/page', e => {
  if (e.error_code) {
    //message.error(e.user_message);
    return null;
  }
  return {
    data: e.items.map(it => {
      return {
        taskNo: it.task_id,
        app: it.app_name || it.app_id,
        chunk: it.module,
        taskStatus: it.state,
        operator: it.operator,
        createDate: it.created_at,
        progress: it.progress,
        ...it,
      };
    }),
    success: true,
  };
});
